package main

import "fmt"

type Person struct {
	Name string
	Sex  byte
	Age  int
}

type Person2 struct {
	Name string
}

type Student struct {
	Person
	//Person2
	addr string
}

func (person *Person) printInfo() {
	fmt.Printf("name=%s, sex=%d, age=%d\n", person.Name, person.Sex, person.Age)
}
func (person *Person2) printInfo() {
	fmt.Printf("p2name=%s\n", person.Name)
}

func (student *Student) printInfo() {
	fmt.Printf("name=%s, sex=%d, age=%d, addr=%s\n", student.Name, student.Sex, student.Age, student.addr)
}

func main() {
	s := Student{
		Person: Person{
			Name: "xdc",
			Sex:  1,
			Age:  2,
		},
		//Person2: Person2{Name: "p2name"},
		addr: "beijing",
	}
	// 就近原则， 先找本作用域的方法，找不到在用继承的方法
	// 如果继承了多个，没有重写 报错 .\12_方法的重写.go:44:3: ambiguous selector s.printInfo
	s.printInfo()

	// 继承多个，同时字段名字相同， 报错 Ambiguous reference 'Name'
	fmt.Println(s.Name)

	// 如果非要调用父类的方法
	s.Person.printInfo()
}
